package org.lc.stk.model.banks;

import java.util.List;

import org.hibernate.annotations.Comment;
import org.lc.stk.model.paper.attr.PaperTemplate;
import org.lc.stk.model.question.attrs.DifficultySchema;
import org.lc.stk.model.question.attrs.QuestionType;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinTable;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;

/**
 * 试题库、试卷库基类
 */
@Entity
@Table(name = "banks")
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Bank {

    public enum BankState {
        ACTIVE(1),
        INACTIVE(0);
        private final int value;
        BankState(int value) {
            this.value = value;
        }
        public int getValue() {
            return value;
        }
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Integer id;

    @Column(name = "name", nullable = false)
    @Comment("题库名称")
    private String name;

    @Column(name = "state", nullable = false)
    @Comment("状态：1-在用，0-停用")
    private Integer state;

    @Column
    private Integer type;

    @ManyToMany
    @JoinTable(
        name = "bank_question_type",
        joinColumns = @JoinColumn(name = "bank_id"),
        inverseJoinColumns = @JoinColumn(name = "question_type_id")
    )
    @Comment("题型列表")
    private List<QuestionType> questionTypes;

    @ManyToOne
    @JoinColumn(name = "difficulty_schema_id")
    @Comment("难度方案")
    private DifficultySchema difficultySchema;

    // 试卷模板
    @ManyToMany
    @JoinTable(
        name = "bank_paper_template",
        joinColumns = @JoinColumn(name = "bank_id"),
        inverseJoinColumns = @JoinColumn(name = "paper_template_id")
    )
    private List<PaperTemplate> paperTemplates;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getState() {
        return state;
    }

    public void setState(BankState state) {
        this.state = state.getValue();
    }

    public List<QuestionType> getQuestionTypes() {
        return questionTypes;
    }

    public void setQuestionTypes(List<QuestionType> questionTypes) {
        this.questionTypes = questionTypes;
    }

    public DifficultySchema getDifficultySchema() {
        return difficultySchema;
    }

    public void setDifficultySchema(DifficultySchema difficultySchema) {
        this.difficultySchema = difficultySchema;
    }

    public List<PaperTemplate> getPaperTemplates() {
        return paperTemplates;
    }

    public void setPaperTemplates(List<PaperTemplate> paperTemplates) {
        this.paperTemplates = paperTemplates;
    }

    public Integer getType() {
        return type;
    }
    
    public void setType(Integer type) {
        this.type = type;
    }

}
